/*
 * AssetManager.cpp
 *
 *  Created on: 08/01/2012
 *      Author: Mariano
 */

#include "AssetManager.h"
using namespace std;
AssetManager::AssetManager() {
}

AssetManager::~AssetManager() {
}

SDL_Surface* AssetManager::loadTexture(string filename) {
	//Temporary storage for the image that's loaded
	SDL_Surface* loadedImage = NULL;
	//The optimized image that will be used
	SDL_Surface* optimizedImage = NULL;
	//Load the image
	loadedImage = IMG_Load(filename.c_str());
	//If nothing went wrong in loading the image
	if (loadedImage != NULL) {
		//Create an optimized image
		optimizedImage = SDL_DisplayFormat(loadedImage);
		//Push optimizedImage to "surfaces"
		surfaces.push_back(optimizedImage);
		//Free the old image
		SDL_FreeSurface(loadedImage);
		//Return the optimized image
		return optimizedImage;
	} else {
		return NULL;
	}

}

void AssetManager::cleanUpTextures() {
	list<SDL_Surface *>::iterator s;
	for (s = surfaces.begin(); s != surfaces.end(); s++) {
		SDL_FreeSurface(*s);
	}
}

Sprite* AssetManager::loadSprite(string filename, int frameCount, int spriteW,
		int spriteH) {
	Sprite* sprite = new Sprite(loadTexture(filename), frameCount, spriteW,
			spriteH);
	return sprite;
}
